﻿package mortal.game.view.palyer.data
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import extend.language.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.Title.data.*;
    import mortal.game.view.common.util.*;

    public class TitleUtil extends Object
    {
        private static var _gainAttrArr:Array = ["gainLife", "gainMagic", "gainAttack", "gainPhysDefense", "gainMagicDefense", "gainPenetration", "gainHit", "gainJouk", "gainCrit", "gainToughness", "gainExpertise", "gainBlock"];
        private static var _wareAttrArr:Array = ["wareLife", "wareMagic", "wareAttack", "warePhysDefense", "wareMagicDefense", "warePenetration", "wareHit", "wareJouk", "wareCrit", "wareToughness", "wareExpertise", "wareBlock"];

        public function TitleUtil()
        {
            return;
        }// end function

        public static function getTotalGainAttrData() : Array
        {
            var _loc_3:String = null;
            var _loc_4:TitleDataInfo = null;
            var _loc_5:Array = null;
            var _loc_6:String = null;
            var _loc_7:int = 0;
            var _loc_8:Object = null;
            var _loc_1:* = Cache.instance.title.getDataByType(PlayerConst.TitleType_Own);
            var _loc_2:* = new HashMap();
            for each (_loc_3 in _gainAttrArr)
            {
                
                _loc_2.push(_loc_3, 0);
            }
            for each (_loc_4 in _loc_1)
            {
                
                if (_loc_4.titleStatus != ETitleState._ETitleStateNotGet)
                {
                    for each (_loc_6 in _gainAttrArr)
                    {
                        
                        _loc_7 = _loc_2.getValue(_loc_6) + _loc_4.titleData[_loc_6];
                        _loc_2.push(_loc_6, _loc_7);
                    }
                }
            }
            _loc_5 = [];
            for each (_loc_6 in _loc_2.keys)
            {
                
                _loc_8 = {};
                _loc_8["attrName"] = _loc_6;
                _loc_8["attrValue"] = _loc_2.getValue(_loc_6);
                _loc_8["isTotal"] = true;
                _loc_5.push(_loc_8);
            }
            transAttrName(_loc_5);
            return _loc_5;
        }// end function

        public static function getTotalGainAttrData2() : Array
        {
            var _loc_3:String = null;
            var _loc_4:TitleDataInfo = null;
            var _loc_5:Array = null;
            var _loc_6:String = null;
            var _loc_7:int = 0;
            var _loc_8:TitleAttrData = null;
            var _loc_1:* = Cache.instance.title.getDataByType(PlayerConst.TitleType_Own);
            var _loc_2:* = new HashMap();
            for each (_loc_3 in _gainAttrArr)
            {
                
                _loc_2.push(_loc_3, 0);
            }
            for each (_loc_4 in _loc_1)
            {
                
                if (_loc_4.titleStatus != ETitleState._ETitleStateNotGet)
                {
                    for each (_loc_6 in _gainAttrArr)
                    {
                        
                        _loc_7 = _loc_2.getValue(_loc_6) + _loc_4.titleData[_loc_6];
                        _loc_2.push(_loc_6, _loc_7);
                    }
                }
            }
            _loc_5 = [];
            for each (_loc_6 in _loc_2.keys)
            {
                
                _loc_8 = new TitleAttrData();
                _loc_8.attrName = _loc_6;
                _loc_8.attrValue = _loc_2.getValue(_loc_6) as int;
                _loc_5.push(_loc_8);
            }
            transAttrName(_loc_5);
            return _loc_5;
        }// end function

        public static function getTitleAttrData(param1:TTitle, param2:int = 0) : Array
        {
            var _loc_6:Object = null;
            var _loc_3:Array = [];
            var _loc_4:Array = [];
            if (param2 == 0)
            {
                _loc_4 = _gainAttrArr;
            }
            else
            {
                _loc_4 = _wareAttrArr;
            }
            var _loc_5:int = 0;
            while (_loc_5 < _loc_4.length)
            {
                
                _loc_6 = {};
                _loc_6["attrName"] = _loc_4[_loc_5];
                _loc_6["attrValue"] = param1[_loc_4[_loc_5]];
                _loc_3.push(_loc_6);
                _loc_5++;
            }
            transAttrName(_loc_3, false);
            return _loc_3;
        }// end function

        public static function getTitleAttrData2(param1:TTitle) : Array
        {
            var _loc_4:TitleAttrData = null;
            var _loc_2:Array = [];
            var _loc_3:int = 0;
            while (_loc_3 < _wareAttrArr.length)
            {
                
                if (param1[_wareAttrArr[_loc_3]] != 0)
                {
                    _loc_4 = new TitleAttrData();
                    _loc_4.attrName = _wareAttrArr[_loc_3];
                    _loc_4.attrValue = param1[_wareAttrArr[_loc_3]];
                    _loc_2.push(_loc_4);
                }
                _loc_3++;
            }
            transAttrName(_loc_2);
            return _loc_2;
        }// end function

        public static function judgeOwnAttr(param1:TTitle, param2:int) : Boolean
        {
            var _loc_3:Array = null;
            var _loc_4:int = 0;
            var _loc_5:String = null;
            if (param2 == 0)
            {
                _loc_3 = _gainAttrArr;
            }
            else
            {
                _loc_3 = _wareAttrArr;
            }
            for each (_loc_5 in _loc_3)
            {
                
                _loc_4 = _loc_4 + param1[_loc_5];
            }
            if (_loc_4 != 0)
            {
                return true;
            }
            return false;
        }// end function

        private static function transAttrName(param1:Array, param2:Boolean = true) : void
        {
            var _loc_4:Object = null;
            var _loc_5:String = null;
            var _loc_6:String = null;
            var _loc_7:String = null;
            var _loc_3:* = param2 ? (0) : (1);
            for each (_loc_4 in param1)
            {
                
                _loc_5 = _loc_4["attrName"];
                _loc_6 = _loc_5.substring(4);
                if (param2)
                {
                    _loc_7 = GameDefConfig.instance.getAttributeName(_loc_6, true, _loc_3);
                }
                else
                {
                    _loc_7 = AttributeUtil.transferAttrName(_loc_6);
                }
                _loc_4["attrName"] = _loc_7;
            }
            return;
        }// end function

        public static function showTitleTips(param1:TitleDataInfo, param2:int) : void
        {
            var attrName:String;
            var onUseTitle:Function;
            var i:int;
            var displayName:String;
            var attrValue:int;
            var descStr:String;
            var title:* = param1;
            var type:* = param2;
            onUseTitle = function (param1:int) : void
            {
                if (param1 == Alert.OK)
                {
                    GameProxy.titleProxy.enableTitle(title.titleData.titleId);
                }
                return;
            }// end function
            ;
            var desc:* = Language.getString(35515) + "<font color=\'#00ff00\'>" + title.titleData.name + "</font><br/><br/>";
            var contentDesc:String;
            var attrArr:Array;
            var _loc_4:int = 0;
            var _loc_5:* = _wareAttrArr;
            while (_loc_5 in _loc_4)
            {
                
                attrName = _loc_5[_loc_4];
                if (title.titleData[attrName] != 0)
                {
                    attrArr.push(attrName);
                }
            }
            if (attrArr.length != 0)
            {
                i;
                while (i < attrArr.length)
                {
                    
                    displayName = AttributeUtil.transferAttrName(attrArr[i].substring(4));
                    attrValue = title.titleData[attrArr[i]];
                    contentDesc = contentDesc + ("<font color=\'#ff0000\'>" + displayName + "：</font>");
                    contentDesc = contentDesc + ("<font color=\'#00ff00\'>+" + attrValue + "&#9;&#9;</font>");
                    if ((i + 1) % 2 == 0)
                    {
                        contentDesc = contentDesc + "<br/>";
                    }
                    i = (i + 1);
                }
            }
            else
            {
                descStr = title.titleData.descStr == null ? ("") : (title.titleData.descStr);
                contentDesc = contentDesc + descStr;
            }
            desc = desc + contentDesc;
            desc = desc + Language.getString(35516);
            if (type == EUpdateType._EUpdateTypeAdd)
            {
                Alert.show(desc, null, Alert.OK | Alert.CANCEL, null, onUseTitle);
            }
            return;
        }// end function

        public static function isWinePartyTitle(param1:int) : Boolean
        {
            if (param1 == GameConst.WinePartyTitleId_Drunk || param1 == GameConst.WinePartyTitleId_Man || param1 == GameConst.WinePartyTitleId_Woman)
            {
                return true;
            }
            return false;
        }// end function

        public static function isPlatformTitle(param1:int) : Boolean
        {
            if (param1 == GameConst.PlatformTitleId_YY)
            {
                return true;
            }
            return false;
        }// end function

        public static function isPlatFormMeet(param1:TTitle) : Boolean
        {
            var _loc_2:* = param1.proxyId.split("#");
            var _loc_3:* = Cache.instance.role.roleEntityInfo.entityInfo.entityId.typeEx2;
            if (_loc_2.indexOf(_loc_3.toString()) != -1)
            {
                return true;
            }
            return false;
        }// end function

    }
}
